package com.tuni.birthdaymoney.web.model;

import org.joda.time.DateTime;
import org.springframework.security.web.authentication.session.SessionAuthenticationException;

import com.tuni.birthdaymoney.persistence.entity.Person;
import com.tuni.birthdaymoney.persistence.entity.User;

public class MasterPage {

    private String greeting;
    private DateTime now;

    public MasterPage(User user, boolean allowAnonymousAccess) {
        String username = "Unknown";
        if (user != null) {
            Person person = user.getPerson();
            if (person != null) {
                username = person.createFullName();
            }
        } else if (!allowAnonymousAccess) {
            // perform logout
            throw new SessionAuthenticationException(username);
        }
        greeting = String.format("Welcome, dear %s!", username);
        now = new DateTime();
    }

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }

    public DateTime getNow() {
        return now;
    }

    public void setNow(DateTime now) {
        this.now = now;
    }

}